#include "ZTimer.h"
namespace ZuiLib
{

ZTimer::ZTimer(void)
	:m_timerId(0)
{
}


ZTimer::~ZTimer(void)
{
	KillTimer();
}

Uint32 ZTimer::TimerCallback(Uint32 interval, void *param)
{
	ZTimer* pThis=static_cast<ZTimer*>(param);
	Uint32 rslt=0;
	if (pThis->m_callback)
	{
		rslt=pThis->m_callback->OnTimer(pThis,interval);
	}
	return rslt;
}

void ZTimer::SetTimer(ZTimerCallback* callback,Uint32 interval)
{
	KillTimer();
	m_callback=callback;
	SDL_AddTimer(interval,TimerCallback,this);
}

void ZTimer::KillTimer()
{
	if (m_timerId!=0)
	{
		SDL_RemoveTimer(m_timerId);
		m_timerId=0;
	}
}









}